package cn.qicaiwang.open.app.server.Impl;

import cn.qicaiwang.open.app.dto.PageDTO;
import cn.qicaiwang.open.app.entity.FaBanner;
import cn.qicaiwang.open.app.mapper.FaBannerMapper;
import cn.qicaiwang.open.app.server.DataManagerService;
import cn.qicaiwang.open.common.enums.ResultStatusCodeEnum;
import cn.qicaiwang.open.common.response.ResponseResult;
/*import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;*/
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class DataManagerServiceImpl implements DataManagerService {

    @Resource
    FaBannerMapper faBannerMapper;

    @Override
    public ResponseResult addOrEditInBanner(FaBanner faBanner) {
        ResponseResult res=new ResponseResult(ResultStatusCodeEnum.HTTP_ERROR.getCode(),ResultStatusCodeEnum.HTTP_ERROR.getDesc());

        //数据中有id则更新 无id则插入
        int i;
        if(faBanner.getId()!=null){
            faBanner.setUpdatedAt(new Date());
            i=faBannerMapper.updateByPrimaryKeySelective(faBanner);
        }else{
            faBanner.setCreatedAt(new Date());
            i=faBannerMapper.insertSelective(faBanner);
        }

        if(i!=-1){
            res.setCode(ResultStatusCodeEnum.HTTP_SUCCESS.getCode());
            res.setMsg(ResultStatusCodeEnum.HTTP_SUCCESS.getDesc());
        }
        return res;
    }

    @Override
    public ResponseResult delBanner(int id) {
        ResponseResult res=new ResponseResult(ResultStatusCodeEnum.HTTP_ERROR.getCode(),ResultStatusCodeEnum.HTTP_ERROR.getDesc());
        int i= faBannerMapper.deleteByPrimaryKey((long)id);
        if(i>0){
            res.setCode(ResultStatusCodeEnum.HTTP_SUCCESS.getCode());
            res.setMsg(ResultStatusCodeEnum.HTTP_SUCCESS.getDesc());
        }
        return res;
    }

    @Override
    public Page<FaBanner> getFaBannerList(FaBanner faBanner, Page page) {

        Page<FaBanner> faBanners =faBannerMapper.getFaBannerList(faBanner,page);

        return faBanners;

    }
}
